package com.ruoyi.common.utils;

import java.math.BigDecimal;
import java.util.Random;

/**
 * @version v1.0
 * @ProjectName: ruoyi-vue-plus
 * @ClassName: LocationUtils
 * @Description: TODO(地图坐标距离计算)
 * @Author: Yanghaha
 * @Date: 2021/6/4 14:20
 */
public class LocationUtils {

    private static double EARTH_RADIUS = 6378.137;

    private static double rad(double d) {
        return d * Math.PI / 180.0;
    }

    /**
     * 通过经纬度获取距离(单位：米)
     *
     * @param lng1 经度1
     * @param lat1 纬度1
     * @param lng2 经度2
     * @param lat2 纬度2
     * @return
     */
    public static double getDistance(double lng1, double lat1, double lng2,
                                     double lat2) {
        double radLat1 = rad(lat1);
        double radLat2 = rad(lat2);
        double a = radLat1 - radLat2;
        double b = rad(lng1) - rad(lng2);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
                + Math.cos(radLat1) * Math.cos(radLat2)
                * Math.pow(Math.sin(b / 2), 2)));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000d) / 10000d;
        s = s * 1000;
        BigDecimal big = new BigDecimal(s);
        return big.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    public static void main(String[] args) {
//        double lng1 = 125.114882932251;
//        double lat1 = 48.628478163723;
//        double lng2 = 131.470899171025;
//        double lat2 = 49.276072271069;
//        double distance = getDistance(lng1, lat1, lng2, lat2);
//        System.out.println("distanc:" + distance);

        // pritNoBug();
        // forEachXX();
    }

//    public static void pritNoBug() {
//        System.out.println(" ......................我佛慈悲......................");
//        System.out.println("                       _oo0oo_                      ");
//        System.out.println("                      o8888888o                     ");
//        System.out.println("                      88\" . \"88                     ");
//        System.out.println("                      (| -_- |)                     ");
//        System.out.println("                      0\\  =  /0                     ");
//        System.out.println("                    ___/‘---’\\___                   ");
//        System.out.println("                  .' \\|       |/ '.                 ");
//        System.out.println("                 / \\\\|||  :  |||// \\                ");
//        System.out.println("                / _||||| -卍-|||||_ \\               ");
//        System.out.println("               |   | \\\\\\  -  /// |   |              ");
//        System.out.println("               | \\_|  ''\\---/''  |_/ |              ");
//        System.out.println("               \\  .-\\__  '-'  ___/-. /              ");
//        System.out.println("             ___'. .'  /--.--\\  '. .'___            ");
//        System.out.println("          .\"\" ‘<  ‘.___\\_<|>_/___.’ >’ \"\".          ");
//        System.out.println("         | | :  ‘- \\‘.;‘\\ _ /’;.’/ - ’ : | |        ");
//        System.out.println("         \\  \\ ‘_.   \\_ __\\ /__ _/   .-’ /  /        ");
//        System.out.println("     =====‘-.____‘.___ \\_____/___.-’___.-’=====     ");
//        System.out.println("                       ‘=---=’                      ");
//        System.out.println("                                                    ");
//        System.out.println("....................佛祖开光 ,永无BUG...................");
//    }
//
//    public static void forEachXX() {
//        long begin=System.currentTimeMillis();
//        String[] ee = {"的确", "绝壁", "确实", "有一说一，确实", "我也觉得", "大家都觉得", "这还用说？肯定", "就是个", "呵，", "哦，"};
//        Random r = new Random();
//        for (int j = 0, i = 0; j < 10; j++) {
//            i = r.nextInt(10);
//            System.out.println("关于熊头," + ee[i] + "傻逼！");
//        }
//        long timeValue = System.currentTimeMillis() - begin;
//        System.out.println("耗时：" + timeValue + "毫秒");
//    }
}

